using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TextLang : MonoBehaviour
{
    private static Dictionary<int, TextLang> _dict = new Dictionary<int, TextLang>(100);
    private static int id = 1;
    public string LangId;
    private int _id;
    private Text _text;
    private void Awake()
    {
        if (string.IsNullOrEmpty(LangId)) return;
        _text = GetComponent<Text>();
        if (_text == null) return;
        _id = id++;
        _dict.Add(_id, this);
        UpdateLang();
    }
    private void OnDestroy()
    {
        _dict.Remove(_id);
    }
    private void UpdateLang()
    {
        var txt = GameEntry.Table.Lang.Get(LangId);
        if (txt == null) return;
        _text.text = txt.Text;
    }
    public static void UpdateAll()
    {
        foreach (var item in _dict)
        {
            item.Value.UpdateLang();
        }
    }
}